from openai import OpenAI

client = OpenAI(base_url="http://192.168.2.112:8080/v1", api_key="helloworld")

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Get the current weather in a given location",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA",
                    },
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
                },
                "required": ["location"],
            },
        }
    }
]
messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]
completion = client.chat.completions.create(
    model="gpt-4o",
    messages=messages,
    tools=tools,
    tool_choice="required"
)
agent_chooses = completion.choices
agent_chose_count = len(agent_chooses)

for chose in agent_chooses:
    agent_chose_message = chose.message
    agent_tool_calls = agent_chose_message.tool_calls
    print("agent call counts of tools:", len(agent_tool_calls))
    for tool_call in agent_tool_calls:
        call_function = tool_call.function
        call_function_name = call_function.name
        call_function_arguments = call_function.arguments
        print(call_function_name, call_function_arguments)
